package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"shop/api/request"
	"shop/common/global"
	"shop/shop_grpc/proto/shop"
)

func CreateSeckillGoods(c *gin.Context) {
	var dev request.CreateSeckillGoodsRequest
	if err := c.ShouldBind(&dev); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	goods, err := global.ShopClient.CreateSeckillGoods(c, &shop.CreateSeckillGoodsRequest{
		GoodsId:      int64(dev.GoodsId),
		SeckillStock: int64(dev.SeckillStock),
		SeckillPrice: float32(dev.SeckillPrice),
		BeginTime:    dev.BeginTime,
		EndTime:      dev.EndTime,
	})
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": http.StatusBadRequest,
			"msg":  err.Error(),
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"data": goods,
	})
}
